package com.liang.cloud.Controller;

import com.liang.cloud.Dto.OrderDTO;
import com.liang.cloud.Service.OrderService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: 余亮亮
 * @description:
 * @create: 2020-03-26 12:43:15
 **/
@RestController
@RequestMapping("/order/api")
public class ApiOrderController {

    @Resource
    OrderService service;

    @PostMapping("/create")
    OrderDTO create(@RequestBody OrderDTO orderDTO){
        return service.create(orderDTO);
    }


    @GetMapping("/findOne/{orderId}")
    OrderDTO findOne(@PathVariable("orderId") String orderId){
        return service.findOne(orderId);
    }


    @GetMapping("/findListWithOpenid")
    Page<OrderDTO> findListWithOpenid(String buyerOpenid, Pageable pageable){
        return service.findListWithOpenid(buyerOpenid,pageable);
    }


    @PostMapping("/cancel")
    OrderDTO cancel(@RequestBody OrderDTO orderDTO){
        return service.cancel(orderDTO);
    }


    @PostMapping("/finish")
    OrderDTO finish(@RequestBody OrderDTO orderDTO){
        return service.finish(orderDTO);
    }

    @PostMapping("/paid")
    OrderDTO paid(@RequestBody OrderDTO orderDTO){
        return service.paid(orderDTO);
    }


    @GetMapping("/findList")
    Page<OrderDTO> findList(Pageable pageable){
        return service.findList(pageable);
    }

    @GetMapping("/findOneWithSafe/{orderId}")
    OrderDTO findOneWithSafe(@PathVariable("openid") String openid, @PathVariable("orderId") String orderId){
        return service.findOne(openid, orderId);
    }


    @PostMapping("/cancelWithSafe")
    OrderDTO cancel(@PathVariable("openid")String openid, @PathVariable("orderId") String orderId){
        return service.cancel(openid,orderId);
    }



    @GetMapping("/findByOpenid/{openid}")
    List<OrderDTO> findByOpenid(@PathVariable("openid") String openid){
        return service.findByOpenid(openid);
    }
}
